var utility = {
    scope: {}
};

utility.defineProperty = "function" == typeof Object.defineProperties ? Object.defineProperty : function(target, property, descriptor) {
    if (descriptor.get || descriptor.set) throw new TypeError("ES3 does not support getters and setters.");
    target != Array.prototype && target != Object.prototype && (target[property] = descriptor.value);
}, utility.getGlobal = function(target) {
    return "undefined" != typeof window && window === target ? target : "undefined" != typeof global ? global : target;
}, utility.global = utility.getGlobal(void 0), utility.SYMBOL_PREFIX = "jscomp_symbol_", utility.initSymbol = function() {
    utility.initSymbol = function() {}, utility.global.Symbol || (utility.global.Symbol = utility.Symbol);
}, utility.symbolCounter_ = 0, utility.Symbol = function(description) {
    return utility.SYMBOL_PREFIX + (description || "") + utility.symbolCounter_++;
}, utility.initSymbolIterator = function() {
    utility.initSymbol();
    var iteratorSymbol = utility.global.Symbol.iterator;
    iteratorSymbol || (iteratorSymbol = utility.global.Symbol.iterator = utility.global.Symbol("iterator")), "function" != typeof Array.prototype[iteratorSymbol] && utility.defineProperty(Array.prototype, iteratorSymbol, {
        configurable: !0,
        writable: !0,
        value: function() {
            return utility.arrayIterator(this);
        }
    }), utility.initSymbolIterator = function() {};
}, utility.arrayIterator = function(array) {
    var index = 0;
    return utility.iteratorPrototype(function() {
        return index < array.length ? {
            done: !1,
            value: array[index++]
        } : {
            done: !0
        };
    });
}, utility.iteratorPrototype = function(nextFunction) {
    return utility.initSymbolIterator(), (nextFunction = {
        next: nextFunction
    })[utility.global.Symbol.iterator] = function() {
        return this;
    }, nextFunction;
}, utility.makeIterator = function(iterable) {
    utility.initSymbolIterator();
    var iterator = iterable[Symbol.iterator];
    return iterator ? iterator.call(iterable) : utility.arrayIterator(iterable);
}, utility.arrayFromIterator = function(iterator) {
    for (var result, array = []; !(result = iterator.next()).done; ) array.push(result.value);
    return array;
}, utility.arrayFromIterable = function(iterable) {
    return iterable instanceof Array ? iterable : utility.arrayFromIterator(utility.makeIterator(iterable));
};

var appInstance = getApp(), dataProvider = require("../../provider/dataApi.js");

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        list: [],
        page: 1,
        totalPage: 1,
        isData: !0,
        isloading: !0
    },
    onLoad: function(options) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }), this.getExamList(1);
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    getExamList: function(pageNumber) {
        var that = this;
        dataProvider.myTest({
            uid: wx.getStorageSync("uid"),
            page: pageNumber
        }).then(function(response) {
            console.log(response);
            var combinedList = [].concat(utility.arrayFromIterable(that.data.list), utility.arrayFromIterable(response.data.list));
            var totalPages = Math.ceil(response.data.total / response.data.psize);
            var hasData = !1;
            0 < combinedList.length && (hasData = !0), that.setData({
                list: combinedList,
                totalPage: totalPages,
                isData: hasData,
                isloading: !1
            }), wx.stopPullDownRefresh();
        }).catch(function(error) {
            console.log(error);
        });
    },
    seeError: function(event) {
        var item = event.currentTarget.dataset.item;
        1 == item.is_simple && 2 == item.complete ? this.showTip("试卷中包含主观题，请耐心等待评卷") : (appInstance.globalData.op = "seeErr", 
        appInstance.globalData.paperId = item.examid, console.log(item.examid), wx.navigateTo({
            url: "/pages/practice/practice"
        }));
    },
    goResult: function(event) {
        var item = event.currentTarget.dataset.item;
        1 == item.is_simple && 2 == item.complete ? this.showTip("试卷中包含主观题，请耐心等待评卷") : wx.navigateTo({
            url: "/pages/result/result?type=2&paperid=" + item.id + "&id=" + item.rid
        });
    },
    showTip: function(message) {
        wx.showModal({
            title: "提示",
            content: message,
            showCancel: !1,
            confirmText: "关闭",
            success: function(response) {
                console.log(response);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.setData({
            page: 1,
            list: [],
            isloading: !0
        }), this.getExamList(1);
    },
    onReachBottom: function() {
        var totalPages = parseInt(this.data.totalPage), currentPage = parseInt(this.data.page);
        currentPage < totalPages && (this.setData({
            page: currentPage + 1
        }), this.getExamList(this.data.page));
    },
    onShareAppMessage: function() {}
});